/*
 * TODO
 */
package com.xtrip.adm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xtrip.adm.dao.CityDao;
import com.xtrip.adm.model.City;
import com.xtrip.base.BaseDao;
import com.xtrip.base.BaseService;
import com.xtrip.common.BasicConstant;
import com.xtrip.util.IdGenerator;

/**
 * @project xtrip
 * @author shiming.yao
 * @time 2013-5-23
 */
@Service("cityService")
public class CityService extends BaseService<City>{

	@Resource(name="cityDao")
	private CityDao dao;
	//UPDATE tmp_hotel t SET t.cid=(SELECT t1.id FROM tmp_city t1 WHERE t1.tc_cid=t.cid)
	/* (non-Javadoc)
	 * @see com.xtrip.base.BaseService#getDao()
	 */
	@Override
	public BaseDao<City> getDao() {
		// TODO Auto-generated method stub
		return dao;
	}
	public boolean insertCity(City city){
		String id = IdGenerator.generateId(BasicConstant.PREFIX_CITY);
		city.setId(id);
		return dao.insert(city)==1;
	}
	public void updateCity(City city){
		dao.update(city);
	}
	public Map<String,String> getProvinceMap(){
		String sql = "select id,name from adm_province";
		List<Map<String,Object>> list = dao.getFacade().query(sql, null);
		Map<String,String> map = new HashMap<String,String>();
		for(Map<String,Object> m:list){
			String id = m.get("id").toString();
			map.put(m.get("name").toString(), id);
		}
		return map;
	}

}
